Ext.define('AM.view.RewardStockView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.rewardStockView',
		store : 'RewardStockSotre',
		border:false,
		columnLines:true,
//		selModel : Ext.create('Ext.selection.CheckboxModel'), 
		selModel: {
	        injectCheckbox: 0,
	        mode: "SIMPLE"    //"SINGLE"/"SIMPLE"/"MULTI"
	       
   		 },
   		selType: "checkboxmodel",
    	dockedItems: [{
        xtype: 'pagingtoolbar',
        dock: 'bottom',
        store : 'RewardStockSotre',
        displayInfo: true
    }],
		columns: [	
			        {text: '序号', dataIndex: 'id',width:50,align:'center'},
			        { text: '奖金月均存量',  dataIndex: 'toatalfinace',  width:120,align:'center'},
			        { text: '存量年份',dataIndex: 'year', width:120,align:'center'}
			     ],
			   tbar: [ 
					  { xtype: 'button', text: '修改存量',handler: editRewardStock,icon:'Ext/restful/images/cog_edit.png'},
					  { xtype: 'button', text: '增加存量',handler: addRewardStock,icon:'Ext/restful/images/add.png'}
					]
})
function editRewardStock() {
		  var myform1= new Ext.form.Panel({
			        labelWidth : 65,
			        bodyPadding: 30,
			        items: [{
					      	    xtype : "numberfield",
					      	    labelAlign :"right",
					            fieldLabel: '奖金存量',
					            allowBlank:false,
					            name:'toatalfinace',
							    minValue: 0
							},{
							    xtype : "textfield",
					      	    labelAlign :"right",
					            fieldLabel: '年份',
					            allowBlank:false,
					            name:'year'
							},{
								xtype : "textfield",			
					      		labelAlign :"right",
					            fieldLabel: 'ID',
					            allowBlank:false,
					            name: 'id',
					            hidden:true
							}
						]
     	
		 })
			var grid=this.ownerCt.ownerCt;
			var win = new Ext.Window({
				title : "修改奖金存量",
				width : 350,
				height : 200,
				frame:true,
				layout:'fit',
				items : [ myform1
							],
				buttons : [{
							text : "确定",
							handler : function() {
								win.getComponent(0).getForm().submit({
											    url : 'departmentFinaceAction_editRewardStock',
											    success : function() {
												Ext.Msg.alert('提示', '修改成功');
												win.close();
												grid.getStore().reload();
												grid.getSelectionModel().deselectAll();
											},
											failure : function() {
												Ext.Msg.alert('错误', '修改失败');
											},
											waitMsg : "请稍后，正在保存。。。。"
	
										});
							}
						}, {
							text : "重置",
							handler : function() {
								win.getComponent(0).getForm().reset();
							}
						}, {
							text : "取消",
							handler : function() {
								win.close();
											
							}
						}]
			});
		
		var selections = grid.getSelectionModel().getSelection();
						if(selections.length==0){
							Ext.MessageBox.alert("提示","请选择要编辑的一行！");
						}else if (selections.length > 1) {
							Ext.MessageBox.alert("提示", "请检查您是否选中了多行！");
							return;
						} else{
							var record = selections[0];
						//这里是修改操作的实现部分
							win.getComponent(0).getForm().loadRecord(record);
							win.show();
						}
 }

  function addRewardStock() {
   		 var grid=this.ownerCt.ownerCt;
		 var myform1= new Ext.form.Panel({
		 			bodyPadding: 30,
			        labelWidth : 65,
					   items: [{ 
					   		      allowBlank:false,
					   			  xtype : "textfield",
					   		      fieldLabel: '存量年份',
					   			  labelAlign :"right",
							      name: 'year'
							      
							},{
							    xtype : "numberfield",
					      	    labelAlign :"right",
					            fieldLabel: '奖金存量',
					            allowBlank:false,
					            name:'toatalfinace',
							    minValue: 0
							}]		        	
				        	       

		 })
			var win = new Ext.Window({
				title : "添加存量",
				width : 350,
				height : 200,
				frame:true,
				layout:'fit',
				items : [ myform1
							],
				buttons : [{
							text : "确定",
							handler : function() {
								win.getComponent(0).getForm().submit({
											 url : 'departmentFinaceAction_addRewardStock',
											 success : function() {
												Ext.Msg.alert('提示', '添加成功');
												win.close();
												grid.getStore().reload();
//												grid.getSelectionModel().deselectAll();
											},
											failure : function() {
												Ext.Msg.alert('错误', '添加失败');
											},
											waitMsg : "请稍后，正在保存。。。。"
	
										});
							}
						}, {
							text : "重置",
							handler : function() {
								win.getComponent(0).getForm().reset();
							}
						}, {
							text : "取消",
							handler : function() {
												win.close();
											
							}
						}]
			});
		win.show();
}

 	
 
 